<template>
	<view class="data-card" :class="cardClass">
		<view class="card-header">
			<view class="icon-wrapper" :style="{ backgroundColor: iconColor }">
				<u-icon :name="icon" size="24" color="#fff"></u-icon>
			</view>
			<view class="card-info">
				<text class="card-title">{{ title }}</text>
				<text class="card-subtitle" v-if="subtitle">{{ subtitle }}</text>
			</view>
		</view>
		
		<view class="card-content">
			<text class="card-value" :style="{ color: valueColor }">{{ value }}</text>
			<view class="card-trend" v-if="trend">
				<u-icon 
					:name="trend > 0 ? 'arrow-up' : 'arrow-down'" 
					:color="trend > 0 ? '#4CAF50' : '#f44336'"
					size="16"
				></u-icon>
				<text 
					class="trend-text" 
					:style="{ color: trend > 0 ? '#4CAF50' : '#f44336' }"
				>
					{{ Math.abs(trend) }}%
				</text>
			</view>
		</view>
		
		<view class="progress-container" v-if="showProgress">
			<view class="progress-bar">
				<view 
					class="progress-fill" 
					:style="{ 
						width: progress + '%', 
						backgroundColor: progressColor || iconColor 
					}"
				></view>
			</view>
			<text class="progress-text">{{ progressText }}</text>
		</view>
	</view>
</template>

<script>
export default {
	name: 'DataCard',
	props: {
		title: {
			type: String,
			required: true
		},
		subtitle: {
			type: String,
			default: ''
		},
		value: {
			type: [String, Number],
			required: true
		},
		icon: {
			type: String,
			required: true
		},
		iconColor: {
			type: String,
			default: '#2196F3'
		},
		valueColor: {
			type: String,
			default: '#333'
		},
		trend: {
			type: Number,
			default: null
		},
		progress: {
			type: Number,
			default: 0
		},
		progressColor: {
			type: String,
			default: ''
		},
		progressText: {
			type: String,
			default: ''
		},
		showProgress: {
			type: Boolean,
			default: false
		},
		cardClass: {
			type: String,
			default: ''
		}
	}
}
</script>

<style lang="scss" scoped>
.data-card {
	background-color: #fff;
	border-radius: 12px;
	padding: 20px;
	margin-bottom: 15px;
	box-shadow: 0 2px 8px rgba(0,0,0,0.1);
	
	.card-header {
		display: flex;
		align-items: flex-start;
		margin-bottom: 15px;
		
		.icon-wrapper {
			width: 40px;
			height: 40px;
			border-radius: 20px;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-right: 12px;
		}
		
		.card-info {
			flex: 1;
			
			.card-title {
				font-size: 14px;
				color: #666;
				display: block;
				line-height: 1.4;
			}
			
			.card-subtitle {
				font-size: 12px;
				color: #999;
				display: block;
				margin-top: 4px;
			}
		}
	}
	
	.card-content {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 15px;
		
		.card-value {
			font-size: 24px;
			font-weight: bold;
		}
		
		.card-trend {
			display: flex;
			align-items: center;
			
			.trend-text {
				margin-left: 4px;
				font-size: 12px;
				font-weight: 500;
			}
		}
	}
	
	.progress-container {
		.progress-bar {
			height: 4px;
			background-color: #f0f0f0;
			border-radius: 2px;
			overflow: hidden;
			margin-bottom: 8px;
			
			.progress-fill {
				height: 100%;
				border-radius: 2px;
				transition: width 0.3s ease;
			}
		}
		
		.progress-text {
			font-size: 12px;
			color: #999;
		}
	}
}
</style>
